#include "Common.h"
#include "Engine.h"
#include "Root.h"
#include "SceneManager.h"
#include "Scene.h"
#include "Camera.h"
#include "RenderWindow.h"
#include "Game.h"


Engine::Engine()
	: mGame(NULL)
	, mSceneMgr(NULL)
	, mCamera(NULL)
{
	Root::NewInstance();
}

Engine::~Engine(void)
{
	Root::DeleteInstance();
}

bool Engine::Init()
{
	if (!Root::Instance().Init())
		return false;

	mSceneMgr = Root::Instance().CreateSceneManager("Main SceneMgr");
	mCamera = mSceneMgr->getScene()->createCamera("Main Camera");

	Root::Instance().getRenderWindow()->setCamera(mCamera);

	return true;
}

void Engine::Start()
{
	Root::Instance().Start();
}

void Engine::Exit()
{
	if (mSceneMgr != NULL)
	{
		Root::Instance().DestroySceneManager(mSceneMgr);

		mCamera = NULL;
		mSceneMgr = NULL;
	}

	Root::Instance().Exit();
}

void Engine::Update(float elapsedTime)
{
	mGame->Update(elapsedTime);

	mSceneMgr->Update(elapsedTime);
}
